package com.wing.system.service;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wing.system.dao.FloorInfoDao;
import com.wing.system.model.entity.FloorInfo;
import com.wing.system.model.entity.RoomType;
import com.wing.system.model.request.FloorInfoForm;
import com.wing.system.model.response.FloorInfoVO;
import com.wing.system.model.response.RoomTypeVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * 楼层-ServiceImpl
 *
 * @author
 */
@Service
@Slf4j
public class FloorInfoServiceImpl extends ServiceImpl<FloorInfoDao, FloorInfo> implements FloorInfoService {

    @Override
    public int add(FloorInfoForm floorInfoForm) {

        //校验

        FloorInfo floorInfo =new FloorInfo();
        CopyOptions copyOptions = CopyOptions.create()
        .setEditable(FloorInfo.class)
        .setIgnoreError(true)
        .setIgnoreNullValue(true);
        BeanUtil.copyProperties(floorInfoForm, floorInfo, copyOptions);

        return baseMapper.insert(floorInfo);
    }

    @Override
    public List<FloorInfoVO> list4app(Map<String, Object> params) {
        return baseMapper.list4app(params);
    }

    @Override
    public Page<FloorInfoVO> pageList4app(Page page, Map<String, Object> params) {
        List<FloorInfoVO> list = baseMapper.list4app(page, params);
        page.setRecords(list);
        return page;
    }

    @Override
    public FloorInfoVO get4appById(Long id) {
        return baseMapper.get4appById(id);
    }

    @Override
    @Transactional
    public int enable(Long id) {
        FloorInfoVO floorInfoVO=baseMapper.get4appById(id);
        if (floorInfoVO!=null){
            FloorInfo floorInfo=new FloorInfo();
            floorInfo.setId(id);
            floorInfo.setDeleted(true);
            int updateCount=baseMapper.updateById(floorInfo);
            return updateCount;
        }

        return 0;
    }

    @Override
    @Transactional
    public int disable(Long id) {
        FloorInfoVO floorInfoVO=baseMapper.get4appById(id);
        if (floorInfoVO!=null){
            FloorInfo floorInfo=new FloorInfo();
            floorInfo.setId(id);
            floorInfo.setDeleted(false);
            int updateCount=baseMapper.updateById(floorInfo);
            return updateCount;
        }
        return 0;
    }
}
